package WebServices
{
	import DataModel.SkillsAuditDocument;
	
	import flash.net.URLVariables;
	
	internal class FetchDocumentResponder extends HttpResponder
	{
		public function FetchDocumentResponder(auth:AuthenticationData, success:Function, failure:Function)
		{
			super(auth, success, failure);
		}

		public function callServer(service: SkillsAuditService, docId:String):void
		{
			var xml:XML =
			<EnumDataAccessRequest>
				<SecurityContext>
  					<UserName/> 
  					<UserPasswordMD5Hash/> 
  				</SecurityContext>
  				<DocumentNumber/>
  			</EnumDataAccessRequest>;

  			xml.SecurityContext.UserName = m_authData.username;
  			xml.SecurityContext.UserPasswordMD5Hash = m_authData.getDigest();
  			xml.DocumentNumber = docId;
			service.setCallbacks(onSuccess, onFailure);
			var strXML:String = "xml="+xml.toXMLString();
			var myPattern:RegExp = /&/g;  
			strXML = strXML.replace(myPattern, "%26"); 
			service.request= new URLVariables(strXML);
			service.send();
		}
		
		override protected function onSuccess(xmlResponse:XML):void
		{
			if(xmlResponse.name().toString() != "EnumDataAccessResponse")
			{
				onFailure(new Error("Invalid root element received from server. Expected 'EnumDataAccessResponse' received '" +xmlResponse.name().toString() + "'"));
				return;
			}
			SkillsAuditDocument.instance.fromXML(xmlResponse);
			super.onSuccess(xmlResponse);
		}

// Test data -- should no longer be needed --PB
//			var testXml:XML =
//			<EnumDataAccessResponse>
//				<EnumData>
//	  				<DocumentNumber>8777</DocumentNumber> 
//	  				<TransactionType>2</TransactionType> 
//					<StationID>
//	  					<MinistryId>24</MinistryId> 
//	  					<MinistryName>Ministry qwerty</MinistryName> 
//	  					<DepartmentId>52</DepartmentId> 
//	    				<DepartmentName>Department Azerty</DepartmentName> 
//	    				<ProvinceId>11</ProvinceId> 
//	    				<ProvinceName>Province 5</ProvinceName> 
//	    				<DistrictId>21</DistrictId> 
//	    				<District>District 9</District> 
//	    				<PayStationId>23</PayStationId> 
//	    				<PayStationName>PayStation 23</PayStationName> 
//	    				<Attendance>3</Attendance> 
//	    				<EnumerationDate>2010-01-01</EnumerationDate> 
//	    				<EnumerationName>Enumerator Name</EnumerationName> 
//	    				<EnumerationSign>true</EnumerationSign> 
//	    			</StationID>
//					<PersonnelID>
//	      				<Title>1 - Mr.</Title> 
//	      				<Surname>Leclerc</Surname> 
//	      				<FirstName>Georges</FirstName> 
//	      				<OtherNames>Erik</OtherNames> 
//	      				<PreviousName>Juszczakiewicz-Leclerc</PreviousName> 
//	      				<NationalId>4561</NationalId> 
//	      				<NSSAId>458934</NSSAId> 
//	      				<ECNumber>3029</ECNumber> 
//	      				<BirthEntryNo>999945</BirthEntryNo> 
//	      				<MedicalAidId>8624</MedicalAidId> 
//	      				<Authorization>Goverment of Canada</Authorization> 
//	      			</PersonnelID>
//					<PersonalInfo>
//	      				<DateBirth>1963-04-04</DateBirth> 
//	      				<DateBirthCheckbox>true</DateBirthCheckbox> 
//	      				<PlaceBirth>Houf</PlaceBirth> 
//	      				<PlaceBirthCheckbox>false</PlaceBirthCheckbox> 
//	      				<City>Houf</City> 
//	      				<CityCheckbox>false</CityCheckbox> 
//	      				<District>Azerty</District> 
//	      				<DistrictCheckbox>false</DistrictCheckbox> 
//	      				<Province>Qwerty T</Province> 
//	      				<ProvinceCheckbox>true</ProvinceCheckbox> 
//	      				<Country>Zimbabwe</Country> 
//	      				<CountryCheckbox>false</CountryCheckbox> 
//	      				<Sex>1</Sex> 
//	      				<SexCheckbox>false</SexCheckbox> 
//	      				<MaritalStatus>Single</MaritalStatus> 
//	      				<MaritalStatusCheckbox>true</MaritalStatusCheckbox> 
//	      				<Nationality>Canadian</Nationality> 
//	      				<NationalityCheckbox>true</NationalityCheckbox> 
//	      				<DocumentUsed>2</DocumentUsed> 
//	      			</PersonalInfo>
//	  				<ContactInfo>
//	      				<Street>120 Promenade</Street> 
//	      				<POBox>12345</POBox> 
//	      				<Suburb>Gatineau</Suburb> 
//	      				<Area>Hull</Area> 
//	      				<HomePhone>(555)555-5555</HomePhone> 
//	      				<WorkPhone>(555)555-1234 ext 345</WorkPhone> 
//	      				<MobilePhone>(555)555-5678</MobilePhone> 
//	      			</ContactInfo>
//	  				<RecordOfEmployment>
//	      				<DateFirstAppt>1973-12-31</DateFirstAppt> 
//	      				<DateFirstApptCheckbox>true</DateFirstApptCheckbox> 
//	      				<ApptLetterDate>1973-04-04</ApptLetterDate> 
//	      				<ApptLetterDateCheckbox>true</ApptLetterDateCheckbox> 
//	      				<DateReappt>1973-04-04</DateReappt> 
//	     				<DateReapptCheckbox>true</DateReapptCheckbox> 
//	      				<DateApptCurr>1973-04-04</DateApptCurr> 
//	      				<DateApptCurrCheckbox>true</DateApptCurrCheckbox> 
//	      				<Designation>string</Designation> 
//	      				<DesignationCheckbox>true</DesignationCheckbox> 
//	      				<CurrentGrade>A9</CurrentGrade> 
//	      				<CurrentGradeCheckbox>true</CurrentGradeCheckbox> 
//	      				<SalaryCode>4296</SalaryCode> 
//	      				<SalaryCodeCheckbox>true</SalaryCodeCheckbox> 
//	      				<GrossMonthSalary>150</GrossMonthSalary> 
//	      				<GrossMonthSalaryCheckbox>true</GrossMonthSalaryCheckbox> 
//	      				<MedicalClearFormDate>1973-04-04</MedicalClearFormDate> 
//	      				<MedicalClearFormDateCheckbox>true</MedicalClearFormDateCheckbox> 
//	      				<PoliceClearFormDate>1973-04-04</PoliceClearFormDate> 
//	      				<PoliceClearFormDateCheckbox>true</PoliceClearFormDateCheckbox> 
//	      				<AppointmentFormDate>1973-04-04</AppointmentFormDate> 
//	      				<ApptFormDateCheckbox>true</ApptFormDateCheckbox> 
//	      				<Passport></Passport> 
//	      				<AppointmentLetter>2</AppointmentLetter> 
//	      				<MedicalClearForm>2</MedicalClearForm> 
//	      				<BirthCertificate>0</BirthCertificate> 
//	      				<AppointmentForm>1</AppointmentForm> 
//	      				<PoliceClearForm>1</PoliceClearForm> 
//	  				</RecordOfEmployment>
//	  				<AcademicQual>
//	  					<id>3</id>
//	      				<DegreeCertif>Secondary Diploma</DegreeCertif> 
//	      				<Institution>Hull Secondary School</Institution> 
//	      				<YearCompleted>1976</YearCompleted> 
//	      				<DocumentName>Diploma</DocumentName> 
//	      				<DocumentState>2</DocumentState> 
//	      			</AcademicQual>
//	  				<AcademicQual>
//	  					<id>2</id>
//	      				<DegreeCertif>Bachelor Degree</DegreeCertif> 
//	      				<Institution>U of S</Institution> 
//	      				<YearCompleted>1980</YearCompleted> 
//	      				<DocumentName>Diploma</DocumentName> 
//	      				<DocumentState>1</DocumentState> 
//	  				</AcademicQual>
//	  				<AcademicQual>
//	  					<id>1</id>
//	      				<DegreeCertif>Master Degree</DegreeCertif> 
//	      				<Institution>U of M</Institution> 
//	      				<YearCompleted>1988</YearCompleted> 
//	      				<DocumentName>Diploma</DocumentName> 
//	      				<DocumentState>1</DocumentState> 
//	  				</AcademicQual>
//	  				<ProfQual>
//	  					<id>1</id>
//	      				<DiplomaCertif>LiveCycle Training</DiplomaCertif> 
//	      				<Institution>4 point</Institution> 
//	      				<YearCompleted>2008</YearCompleted> 
//	      				<DocumentName>Attestation</DocumentName> 
//	      				<DocumentState>0</DocumentState> 
//	  				</ProfQual>
//	  				<ProfQual>
//	  					<id>2</id>
//	      				<DiplomaCertif>Flex training</DiplomaCertif> 
//	      				<Institution>4 point</Institution> 
//	      				<YearCompleted>2008</YearCompleted> 
//	      				<DocumentName>Attestation</DocumentName> 
//	      				<DocumentState>0</DocumentState> 
//	  				</ProfQual>
//	  				<ProfQual>
//	  					<id>3</id>
//	      				<DiplomaCertif>ITIL Foundation</DiplomaCertif> 
//	      				<Institution>U of O</Institution> 
//	      				<YearCompleted>2009</YearCompleted> 
//	      				<DocumentName>Attestation</DocumentName> 
//	      				<DocumentState>2</DocumentState> 
//	  				</ProfQual>
//	  				<InServiceTraining>
//	  					<id>1</id>
//	      				<TrainingCourse>French course</TrainingCourse> 
//	      				<Institution>U of O</Institution> 
//	      				<YearCompleted>2010</YearCompleted> 
//	      				<DocumentName>Subscription form</DocumentName> 
//	      				<DocumentState>1</DocumentState> 
//	  				</InServiceTraining>
//	  				<InServiceTraining>
//	  					<id>2</id>
//	      				<TrainingCourse>Spanish course</TrainingCourse> 
//	      				<Institution>U of O</Institution> 
//	      				<YearCompleted>2009</YearCompleted> 
//	      				<DocumentName>Official exam result</DocumentName> 
//	      				<DocumentState>1</DocumentState> 
//	  				</InServiceTraining>
//	  				<InServiceTraining>
//	  					<id>3</id>
//	      				<TrainingCourse>Italian course</TrainingCourse> 
//	      				<Institution>U of O</Institution> 
//	      				<YearCompleted>2009</YearCompleted> 
//	      				<DocumentName>Official exam result</DocumentName> 
//	      				<DocumentState>1</DocumentState> 
//	  				</InServiceTraining>
//	  				<Notes>
//	  					<Note>
//	  						<RelatedSection>5</RelatedSection> 
//	    					<NoteRef>1</NoteRef> 
//	    					<Observation>An observation on Academic Qualifications</Observation> 
//	    					<Opinion>An opinion on Academic Qualifications</Opinion> 
//	    				</Note>
//	    				<Note>
//	    					<RelatedSection>7</RelatedSection> 
//	    					<NoteRef>2</NoteRef> 
//	    					<Observation>An observation on In-Service Training</Observation> 
//	    					<Opinion>An opinion on In-Service Training</Opinion> 
//	    				</Note>
//	    				<Note>
//	    					<RelatedSection>4</RelatedSection> 
//	    					<NoteRef>3</NoteRef> 
//	    					<Observation>An observation on Academic Qualifications</Observation> 
//	    					<Opinion>An opinion on Record of employment</Opinion> 
//	    				</Note>
//	    				<DateObservations>2010-01-01</DateObservations>
//	    				<ObserverName>Georges Leclerc</ObserverName> 
//	    				<ObserverSign>true</ObserverSign> 
//	    				<DateOpinionGiven>1973-04-04</DateOpinionGiven>
//	    				<OpinionGiverName>Steeve Laberge</OpinionGiverName> 
//	    				<OpinionGiverSign>true</OpinionGiverSign> 
//	    			</Notes>
//	    			<RespondentSign>true</RespondentSign> 
//	    			<AuditorName>Harjit Singh</AuditorName> 
//	    			<AuditorSign>true</AuditorSign> 
//	    			<DataEntryUserName>Philip Baker</DataEntryUserName> 
//	    			<DataEntryUserSign>true</DataEntryUserSign> 
//	    			<DataEntryDate>2010-01-01T00:00:00Z</DataEntryDate>
//	    			<DataVerificationUserName></DataVerificationUserName> 
//	    			<DataVerificationUserSign>false</DataVerificationUserSign> 
//	    			<StatusCode>2</StatusCode>
//	  			</EnumData>
//  			</EnumDataAccessResponse>;
////			xmlResponse = testXml;
		
	}
}